import global from "@/global";
import router, { staticRoutes } from "@/router";
import store from "@/store";
import { useCookie } from "./useCookie";

export interface IUseReset {
    resetRoutes: () => void;
    resetStore: () => void;
    resetCookies: () => void;
    resetAll: () => void;
}

export function useReset(): IUseReset {

    const resetRoutes = () => {
        // 重置路由表
        router.getRoutes().forEach((route) => {
            if (!staticRoutes.find(item => item.path === route.path)) {
                router.removeRoute(route.name);
            }
        })
    }
    const resetStore = () => {
        // 重置userStoreState
        // store.commit('user/_resetUserStoreState');
        // 重置componentsStoreState
        // store.commit('components/_resetComponentsStoreState');
        // 重置permissionStoreState
        // store.commit('permission/_resetPermissionStoreState');
    }
    const resetCookies = () => {
        // 重置cookies
        useCookie().delCookie(global.cookiesTokenName);
    }
    const resetAll = () => {
        resetRoutes();
        resetStore();
        resetCookies();
    }
    return {
        resetRoutes,
        resetStore,
        resetCookies,
        resetAll
    }
}
